<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/5/21
  Time: 22:16
  To change this tproductlate use File | Settings | File Tproductlates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>信息管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link href="/style/basic_layout.css" rel="stylesheet" type="text/css">
    <link href="/style/common_style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/js/jquery/jquery.js"></script>
    <script type="text/javascript" src="/js/plugins/artDialog/jquery.artDialog.js?skin=blue"></script>
    <script type="text/javascript" src="/js/commonAll.js"></script>
    <script type="text/javascript" src="/js/plugins/jquery-validate/jquery.validate.js"></script>
    <script type="text/javascript" src="/js/jquery/jquery.form.min.js"></script>
    <script>
        $(function () {
            //提交时将选中的提交
            $("#editForm").submit(function () {
                $("#select2 option").each(function (index, item) {
                    $(item).prop("selected", true);
                });
            });

            $("#editForm").ajaxForm(function (data) {
                $.dialog({
                    title: "提示",
                    content: data.msg,
                    ok: function () {
                        if (data.success) {
                            window.location.href = "/product/list.do";
                        } else {
                            $.dialog({
                                name: "确定",
                                ok: true
                            })
                        }
                    }
                })

            });
        })
    </script>

    <script>
        $(function () {
            $("#editForm_product").validate({
                rules: {
                    name: {
                        required: true,
                        minlength: 4
                    },
                    password: {
                        required: true,
                        minlength: 6
                    },
                    repassword: {
                        required: true,
                        equalTo: "#password"
                    },
                    email: {
                        required: true,
                        email: true
                    },
                    age: {
                        digits: true,
                        range: [10, 90]
                    }
                },
                messages: {
                    name: {
                        required: "商品名不能为空",
                        minlength: "商品名不能小与4为"
                    },
                    password: {
                        required: "密码不能为空",
                        minlength: "密码长度不能小于6位"
                    },
                    repassword: {
                        required: "确认密码不能为空",
                        equalTo: "两次输入密码不一致"
                    },
                    email: {
                        required: "email不能为空",
                        email: "邮箱格式不正确"
                    },
                    age: {
                        digits: "年龄必须是整数",
                        range: "年龄太小或太大"
                    }

                }
            })
        })
    </script>
</head>
<body>
<form name="editForm_product" enctype="multipart/form-data" action="/product/saveOrUpdate.do" method="post"
      id="editForm">
    <input type="hidden" name="id" value="${product.id}">
    <div id="container">
        <div id="nav_links">
            <span style="color: #1A5CC6;">商品编辑</span>
            <div id="page_close">
                <a>
                    <img src="/images/common/page_close.png" width="20" height="20" style="vertical-align: text-top;"/>
                </a>
            </div>
        </div>
        <div class="ui_content">
            <table cellspacing="0" cellpadding="0" width="100%" align="left" border="0">
                <tr>
                    <td class="ui_text_rt" width="140">商品名</td>
                    <td class="ui_text_lt">
                        <input name="name" value="${product.name}" class="ui_input_txt02"/>
                    </td>
                </tr>
                <tr>
                    <td class="ui_text_rt" width="140">商品编号</td>
                    <td class="ui_text_lt">
                        <input name="sn" value="${product.sn}" class="ui_input_txt02"/>
                    </td>
                </tr>
                <tr>
                    <td class="ui_text_rt" width="140">成本价</td>
                    <td class="ui_text_lt">
                        <input name="costPrice" value="${product.costPrice}" class="ui_input_txt02"/>
                    </td>
                </tr>
                <tr>
                    <td class="ui_text_rt" width="140">销售价</td>
                    <td class="ui_text_lt">
                        <input name="salePrice" value="${product.salePrice}" class="ui_input_txt02"/>
                    </td>
                </tr>
                <tr>
                    <td class="ui_text_rt" width="140">品牌</td>
                    <td class="ui_text_lt">
                        <select name="brandId" class="ui_select01">
                            <c:forEach items="${brands}" var="brand">
                                <option value="${brand.id}" ${brand.id == product.brandId ? "selected" : ''}>${brand.name}</option>
                            </c:forEach>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="ui_text_rt" width="140">商品图片</td>
                    <td class="ui_text_lt">
                        <input type="file" name="img"/>
                        <img src="${product.imagePath}" width="200">
                        <input type="hidden" name="imagePath" value="${product.imagePath}">
                    </td>
                </tr>
                <tr>
                    <td class="ui_text_rt" width="140">商品简介</td>
                    <td class="ui_text_lt">
                        <textarea name="intro" class="ui_input_txtarea">
                            ${product.intro}
                        </textarea>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="ui_text_lt">
                        &nbsp;<input type="submit" value="确定保存" class="ui_input_btn01"/>
                        &nbsp;<input id="cancelbutton" type="button" value="重置" class="ui_input_btn01"/>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</form>
</body>
</html>